﻿using System;
using System.Data;
using System.Collections.Generic;

namespace Chenxin.Lib.House.BLL
{
    /// <summary>
    /// 业务逻辑类House_LockedInfo 的摘要说明。
    /// creator:kimi.dev
    /// date:2010-3-2
    /// </summary>
    public class House_LockedInfo
    {
        public House_LockedInfo()
        { }
        #region  成员方法
        /// <summary>
        /// 添加封盘记录时的操作
        /// </summary>
        public static void Add(Chenxin.Lib.House.Entity.House_LockedInfo model)
        {
            //1.添加封盘记录
            DAL.House_LockedInfo.Add(model);

            //2.更新房源状态
            Entity.House_BaseInfo baseModel = DAL.House_BaseInfo.GetModel(model.HouseId);
            baseModel.UpdateTime = DateTime.Now;
            baseModel.Status = 30;

            DAL.House_BaseInfo.Update(baseModel);

            //2.写入房源跟单

            //3.插入消息通知
                        
            //4.插入系统操作日志
        }

        /// <summary>
        /// 
        /// </summary>
        public static void Update(Chenxin.Lib.House.Entity.House_LockedInfo model)
        {
            DAL.House_LockedInfo.Update(model);
        }

        /// <summary>
        /// 删除一条数据
        /// </summary>
        public void Delete(Guid LockedId)
        {
            DAL.House_LockedInfo.Delete(LockedId);
        }

        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public Chenxin.Lib.House.Entity.House_LockedInfo GetModel(Guid LockedId)
        {
            return DAL.House_LockedInfo.GetModel(LockedId);
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetList(string strWhere)
        {
            return DAL.House_LockedInfo.GetList(strWhere);
        }
        
        /// <summary>
        /// 获得数据列表
        /// </summary>
        public List<Chenxin.Lib.House.Entity.House_LockedInfo> GetModelList(string strWhere)
        {
            DataSet ds = DAL.House_LockedInfo.GetList(strWhere);
            return DataTableToList(ds.Tables[0]);
        }
        /// <summary>
        /// 获得数据列表
        /// </summary>
        public List<Chenxin.Lib.House.Entity.House_LockedInfo> DataTableToList(DataTable dt)
        {
            List<Chenxin.Lib.House.Entity.House_LockedInfo> modelList = new List<Chenxin.Lib.House.Entity.House_LockedInfo>();
            int rowsCount = dt.Rows.Count;
            if (rowsCount > 0)
            {
                Chenxin.Lib.House.Entity.House_LockedInfo model;
                for (int n = 0; n < rowsCount; n++)
                {
                    model = new Chenxin.Lib.House.Entity.House_LockedInfo();
                    if (dt.Rows[n]["LockedId"].ToString() != "")
                    {
                        model.LockedId = new Guid(dt.Rows[n]["LockedId"].ToString());
                    }
                    if (dt.Rows[n]["HouseId"].ToString() != "")
                    {
                        model.HouseId = new Guid(dt.Rows[n]["HouseId"].ToString());
                    }
                    model.HouseCode = dt.Rows[n]["HouseCode"].ToString();
                    model.HouseAddress = dt.Rows[n]["HouseAddress"].ToString();
                    if (dt.Rows[n]["LockedTime"].ToString() != "")
                    {
                        model.LockedTime = DateTime.Parse(dt.Rows[n]["LockedTime"].ToString());
                    }
                    if (dt.Rows[n]["LastTime"].ToString() != "")
                    {
                        model.LastTime = DateTime.Parse(dt.Rows[n]["LastTime"].ToString());
                    }
                    if (dt.Rows[n]["LockedStatus"].ToString() != "")
                    {
                        model.LockedStatus = int.Parse(dt.Rows[n]["LockedStatus"].ToString());
                    }
                    if (dt.Rows[n]["AskerId"].ToString() != "")
                    {
                        model.AskerId = new Guid(dt.Rows[n]["AskerId"].ToString());
                    }
                    model.Asker = dt.Rows[n]["Asker"].ToString();
                    if (dt.Rows[n]["AskerDepartId"].ToString() != "")
                    {
                        model.AskerDepartId = new Guid(dt.Rows[n]["AskerDepartId"].ToString());
                    }
                    model.AskerDepart = dt.Rows[n]["AskerDepart"].ToString();
                    model.Remarks = dt.Rows[n]["Remarks"].ToString();
                    if (dt.Rows[n]["OperatorId"].ToString() != "")
                    {
                        model.OperatorId = new Guid(dt.Rows[n]["OperatorId"].ToString());
                    }
                    model.Operator = dt.Rows[n]["Operator"].ToString();
                    if (dt.Rows[n]["DepartId"].ToString() != "")
                    {
                        model.DepartId = new Guid(dt.Rows[n]["DepartId"].ToString());
                    }
                    model.Department = dt.Rows[n]["Department"].ToString();
                    if (dt.Rows[n]["InputTime"].ToString() != "")
                    {
                        model.InputTime = DateTime.Parse(dt.Rows[n]["InputTime"].ToString());
                    }
                    if (dt.Rows[n]["UpdateTime"].ToString() != "")
                    {
                        model.UpdateTime = DateTime.Parse(dt.Rows[n]["UpdateTime"].ToString());
                    }
                    modelList.Add(model);
                }
            }
            return modelList;
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetAllList()
        {
            return GetList("");
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        //public DataSet GetList(int PageSize,int PageIndex,string strWhere)
        //{
        //return dal.GetList(PageSize,PageIndex,strWhere);
        //}

        #endregion  成员方法
    }
}

